﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="wucCartao.ascx.cs" Inherits="WebControl_wucCartao" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<script type="text/javascript">
    function validar(){
        if (
             (!<%= txtDescricao.ClientID %>.validate()) ||
             (!<%= cbxTipoCartao.ClientID %>.validate()) ||
             (!<%= txtValidadeCartao.ClientID %>.validate()) ||
             (!<%= txtDiaVenctoFatura.ClientID %>.validate())
           )
        {
            //Ext.Msg.alert('Validação de campos', 'O campo descrição é obrigatório.');
            return false;
        }
        return true;
    }
    function deleta(button, e) {
        Ext.Msg.confirm('Exclusão do Registro','Deseja realmente excluir o registro?',
            continueAjaxEvent.createDelegate(button, [button, e], true), 
            button
        );
        return false;
    }
    function continueAjaxEvent(btnId, text, sender, e) {
      if (btnId == 'yes') {
          sender.ajaxEvents.click.fn.apply(sender, [sender, e]);
      }
    }
</script>
<%--Store Para Popular o Grid--%>
<ext:Store ID="strGrid" runat="server" 
    AutoLoad="true"
    RemoteSort="true" 
    OnRefreshData="strGrid_RefreshData">
    <Reader>
        <ext:JsonReader ReaderID="car_Id_Cartao">
            <Fields>
                <ext:RecordField Name="car_Id_Cartao" Type="Int" />
                <ext:RecordField Name="car_tx_NomeCartao" Type="String" />
            </Fields>
        </ext:JsonReader>
    </Reader>
</ext:Store>
<%--Painel como Grid--%>
<ext:Panel ID="pnlCadCartao" runat="server">
    <TopBar>
        <ext:Toolbar runat="server" ID="tbAcoes">
        <Items>
            <ext:ToolbarButton runat="server" ID="btnNovo" 
                Text="Novo"
                Icon="Add">
                <AjaxEvents>
                    <Click OnEvent="NovoClick">
                        <EventMask ShowMask="true" />
                    </Click>
                </AjaxEvents>
            </ext:ToolbarButton>
            <ext:ToolbarButton runat="server" ID="btnEditar" 
                Text="Editar"
                Enabled="false"
                Icon="BuildingEdit">
                <AjaxEvents>
                    <Click OnEvent="EditarClick">
                        <EventMask ShowMask="true" />
                    </Click>
                </AjaxEvents>
            </ext:ToolbarButton>
            <ext:ToolbarFill />
            <ext:ToolbarButton runat="server" ID="btnDeletar"  
                Text="Excluir"
                Enabled="false"
                Icon="Delete">
              <Listeners>
                  <Click Fn="deleta" />
              </Listeners>
              <AjaxEvents>
                  <Click OnEvent="DeletarClick" Success="if (!#{GridCadCartao}.hasSelection()){#{btnDeletar}.disable();} #{GridCadCartao}.reload();">
                  </Click>
              </AjaxEvents>
            </ext:ToolbarButton>
        </Items>    
        </ext:Toolbar>
    </TopBar>
    <Body>
        <ext:GridPanel ID="GridCadCartao" runat="server" 
            StoreID="strGrid" 
            Header="true" 
            Height="150"
            Width="380"
            AutoScroll="true">
            <ColumnModel ID="ColumnModel" runat="server">
                <Columns>
                    <ext:Column ColumnID="car_Id_Cartao" DataIndex="car_Id_Cartao" Header="Código"
                        Width="80" Sortable="true" />
                    <ext:Column DataIndex="car_tx_NomeCartao" Header="Descrição" Width="250" Sortable="true" />
                </Columns>
            </ColumnModel>
            <SelectionModel>
                <ext:RowSelectionModel ID="RowSelectionModel1" SingleSelect="true" runat="server">
                    <Listeners>
                        <RowSelect Handler="#{btnDeletar}.enable(); #{btnEditar}.enable();" />
                        <RowDeselect Handler="#{btnDeletar}.disable(); #{btnEditar}.disable();" />
                        <%--<RowDeselect Handler="if (!#{GridCadCartao}.hasSelection()) {#{btnDeletar}.disable();#{btnEditar}.disable();}" />--%>
                    </Listeners>
                </ext:RowSelectionModel>
            </SelectionModel>
            <LoadMask ShowMask="true" Msg="Carregando..." />
            <SaveMask ShowMask="true" Msg="Salvando..." />
            <BottomBar>
                <ext:PagingToolBar ID="PagingToolBar1" runat="server" PageSize="10" StoreID="strGrid" AutoWidth="true" />
            </BottomBar>
        </ext:GridPanel>
    </Body>
</ext:Panel>
<%--Formulário de Manipulação dos Dados--%>
<ext:Window ID="wdwDadosCartao" runat="server" 
    Title="Dados Cartão" 
    Width="400px"
    Height="250px"
    ShowOnLoad="false"
    Hidden="true"
    Modal="true"
    Resizable="false"
    BodyStyle="padding: 10px">
    <Body>
        <ext:FormLayout ID="FormLayout1" runat="server" LabelWidth="70">
            <ext:Anchor>
                <ext:TextField ID="txtCodigo" runat="server"
                    FieldLabel="Código"
                    AllowBlank="false"
                    MsgTarget="Title"
                    Width="100px">
                </ext:TextField>
            </ext:Anchor>
            <ext:Anchor>
                <ext:TextField ID="txtDescricao" runat="server" 
                    FieldLabel="Descrição"
                    AllowBlank="false"
                    MsgTarget="Side"
                    Width="250px"
                    EmptyText="Informe o nome do cartão">
                </ext:TextField>
            </ext:Anchor>
            <ext:Anchor>
                <ext:ComboBox ID="cbxTipoCartao" runat="server" 
                    FieldLabel="Tipo Cartão"
                    AllowBlank="false"
                    MsgTarget="Title"
                    Width="100px"
                    TriggerAction="All">
                    <Items>
                        <ext:ListItem Text="Crédito" Value="C" />
                        <ext:ListItem Text="Débito" Value="D" />
                        <ext:ListItem Text="Ambos" Value="A" />
                    </Items>
                </ext:ComboBox>
            </ext:Anchor>
            <ext:Anchor>
                <ext:TextField ID="txtNumCartao" runat="server" 
                    FieldLabel="Número"
                    AllowBlank="true"
                    MsgTarget="Side"
                    Width="250px">
                </ext:TextField>
            </ext:Anchor>
            <ext:Anchor>
                <ext:DateField ID="txtValidadeCartao" runat="server"
                    AllowBlank="false"
                    FieldLabel="Validade"
                    MsgTarget="Side"
                    Width="100px">
                </ext:DateField>
            </ext:Anchor>
            <ext:Anchor>
                <ext:NumberField ID="txtDiaVenctoFatura" runat="server" 
                    AllowBlank="false"
                    FieldLabel="Dia Vencto"
                    MsgTarget="Side"
                    Width="100px"
                    EmptyText="da fatura">
                </ext:NumberField>
            </ext:Anchor>
        </ext:FormLayout>
    </Body>
    <BottomBar>
        <ext:Toolbar runat="server" ID="Toolbar1">
            <Items>
                <ext:ToolbarButton ID="btnWindowNovo" runat="server" Text="Novo" Icon="Add">
                    <AjaxEvents>
                        <Click OnEvent="NovoClick"></Click>
                    </AjaxEvents>
                </ext:ToolbarButton>
                <ext:ToolbarButton ID="btnSalvar" runat="server" Text="Salvar" Icon="Disk">
                    <AjaxEvents>
                        <Click OnEvent="SalvarClick" Before="return validar();" Success="#{GridCadCartao}.reload();"></Click>
                    </AjaxEvents>
                </ext:ToolbarButton>
                <ext:ToolbarFill />
                <ext:ToolbarButton ID="btnFechar" runat="server" Text="Fechar" Icon="Cancel">
                    <Listeners>
                        <Click Handler="#{wdwDadosCartao}.hide()" />
                    </Listeners>
                </ext:ToolbarButton>
            </Items>
        </ext:Toolbar>
    </BottomBar>
</ext:Window>
